<?php

class PhpFox_Mod_Video_ComponentAjaxLatest extends BaseComponent
{
    function process()
    {
    	$oReq = &App::getRequest();

    	App::loadClass('Pager');

		$iPageSize = 4;

        if (!$iPageSize)
        {
            $iPage = 0;
            $oUrl->clearParams('iNum');
        }
        else
        {
            $iPage = ($this->getParam('iNum') ? $this->getParam('iNum')  : $oReq->getInt('iNum', 1));
        }
        
        $iTotal = $this->oDatabase->getRow("SELECT COUNT(*) AS count FROM ". App::getT('videos') ."");
		$iCnt = $iTotal['count'];

		$iOffset = $this->oDatabase->_getPageNum($iPage, $iPageSize, $iCnt);

    	$aItems = $this->oDatabase->getRows("SELECT v.vid_id, v.vid_title, u.user FROM
    		". App::getT('videos') ." AS v
    		JOIN ". App::getT('user') ." AS u ON(v.vid_userid = u.id)
    		ORDER BY v.vid_time DESC LIMIT ". $iOffset .",". $iPageSize ."");

		$this->oTpl->assign(array
		(
			'sGImageUrl' => App::getParam('video.image.url'),
			'aItems' => $aItems,
			'iCnt' => $iCnt,
			'iOffset' => $iOffset,
			'iNext' => ($iOffset+$iPageSize)
		));

		return array($this->oTpl->fetch('AjaxLatest.html'), $iCnt);
    }

}

?>